/**
 * <p>Title: ServiceZMCM21.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 贾雪民
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-13 下午06:30:43  贾雪民  Create
 *</pre>
 */

package com.baosight.sczx.zm.cm.service;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.User;
import com.baosight.sczx.common.zm.cInterface.cm.MaterialType;
import com.baosight.sczx.common.zm.cInterface.cs.Engineering;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.common.zm.cInterface.cs.SystemSettingCM;
import com.baosight.sczx.zm.cm.domain.ZMCMTeammaterialplan;

/**区队年需求计划管理
 * <p>Title: ServiceZMCM21.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 贾雪民
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-13 下午06:30:43  贾雪民  Create
 *</pre>
 */

public class ServiceZMCM21 extends ServiceEPBase{

	/**初始数据
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	*/
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cs.units"));
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cm.financeClassify"));
		outInfo.addBlock(User.getInstance().getConstructionStaff("cmes.cm.people", "empCode", "empName", false));
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cm.department", "orgCode", "orgName", false));
		outInfo.addBlock(MaterialType.getMateroalName());
		outInfo.set("orgCode",UserSession.getInSessionProperty("orgCode"));//当前用户所属单位ID
		outInfo.set("orgName",UserSession.getInSessionProperty("orgName"));//当前用户所属单位
		outInfo.set("userId", UserSession.getUserId());//当前登录用户ID
		if(SystemSettingCM.getInstance().getDepartmentId().equals("NULL"))
		{
			outInfo.setStatus(-1);
			outInfo.setMsg("请在系统基础设置的材料使用设置中设定计划审核单位");
			return outInfo;
		}
		outInfo.set("fdAuditDepartmentId",SystemSettingCM.getInstance().getDepartmentId());//审核单位ID

		outInfo.set("isNeedApprover", SystemSettingCM.getInstance().getIsApprover());
		return outInfo;
	}
	
	/**列表查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	*/	
	@Override
	public EiInfo query(EiInfo inInfo) {
		String fdParentId = inInfo.getString("fdParentId");//树节点ID
		StaticTools.setQueryParameters(inInfo,"fdYear",fdParentId,true);//添加查询条件
		StaticTools.setQueryParameters(inInfo,"fdApplicationDeparment",UserSession.getInSessionProperty("orgCode").toString(),true);//添加查询条件
		//StaticTools.setQueryParameters(inInfo,"fdApprovePeople",UserSession.getUserId().toString(),true);//审批人
		
		EiInfo outInfo = super.query(inInfo, "ZMCMTeammaterialplan.query",new ZMCMTeammaterialplan());
		outInfo.addBlock(Engineering.getApplyProject("cmes.cm.applyProject", true));
		return outInfo;
	}

	/**列表新增
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {

		inInfo.getBlock("result").setCell(0, "fdKeyId", TablePk.getInstance().getNextValue("ZMCMTeammaterialplan"));//主键
		inInfo.getBlock("result").setCell(0, "fdPlanStatus", "未上报");
		inInfo.getBlock("result").setCell(0, "fdIsgenerateStockPlan", "否");
		inInfo.getBlock("result").setCell(0, "fdEditor", UserSession.getUserId());
		EiInfo outInfo = super.insert(inInfo, "ZMCMTeammaterialplan.insert");		
		return outInfo;

	}

	/**修改
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		EiInfo outInfo = super.update(inInfo, "ZMCMTeammaterialplan.update");
		return outInfo;
	}	

	/**修改计划状态
	 * <p>Function: update_fdPlanStatus</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	public EiInfo update_fdPlanStatus(EiInfo inInfo) {
		String fdPlanId = inInfo.addBlock("result").getCellStr(0, "fdPlanId");
		inInfo.getBlock("result").setCell(0, "fdPlanId",fdPlanId);
		EiInfo outInfo = super.update(inInfo, "ZMCMTeammaterialplan.update_fdPlanStatus");
		return outInfo;
	}
	
	/**删除
	 * <p>Function: delete</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		EiInfo _temp =super.delete(inInfo,"ZMCMTeammaterialplan.delete","result");
		EiInfo outInfo = this.query(inInfo);
		outInfo.setMsg(_temp.getMsg());
		outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}

	/**
	 * 上报
	 * <p>Function: report</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	public EiInfo report(EiInfo inInfo) {
		  EiInfo _temp = super.update(inInfo, "ZMCMTeammaterialplan.report");
		  EiInfo  outInfo = this.query(inInfo);
	      outInfo.setMsg(_temp.getMsg());
	      outInfo.setDetailMsg(_temp.getDetailMsg());
	      return outInfo;	        
	}	
	
	/**
	 * 撤回
	 * <p>Function: qxreturn</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	public EiInfo qxreturn(EiInfo inInfo) {
		  EiInfo _temp = super.update(inInfo, "ZMCMTeammaterialplan.qxreturn");
		  EiInfo  outInfo = this.query(inInfo);
	      outInfo.setMsg(_temp.getMsg());
	      outInfo.setDetailMsg(_temp.getDetailMsg());
	      return outInfo;
	}	

	/**
	 * 审批
	 * <p>Function: approve</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	public EiInfo approve(EiInfo inInfo) {
		  EiInfo _temp = super.update(inInfo, "ZMCMTeammaterialplan.approve");
		  EiInfo  outInfo = this.query(inInfo);
	      outInfo.setMsg(_temp.getMsg());
	      outInfo.setDetailMsg(_temp.getDetailMsg());
	      return outInfo;
	}
	
	/**
	 * 审核
	 * <p>Function: audit</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-13 下午06:30:43  贾雪民
	 * </p>
	 *
	 */
	public EiInfo audit(EiInfo inInfo) {
		  EiInfo _temp = super.update(inInfo, "ZMCMTeammaterialplan.audit");
		  EiInfo  outInfo = this.query(inInfo);
	      outInfo.setMsg(_temp.getMsg());
	      outInfo.setDetailMsg(_temp.getDetailMsg());
	      return outInfo;
	}
}